home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / misc / bgui12.lha / Classes / AreaClass / testarea.c < prev    next >
C/C++ Source or Header  |  1995-06-02  |  5KB  |  212 lines

  1. ;/* Execute me to compile with DICE v3.0
  2. dcc testarea.c -proto -mi -ms -lareaclass.o -lbgui
  3. quit
  4. */
  5. /*
  6. **           File: testarea.c
  7. **    Description: Very simple test program for the area class.
  8. **      Copyright: (C) Copyright 1994-1995 Jaba Development.
  9. **             (C) Copyright 1994-1995 Jan van den Baard.
  10. **             All Rights Reserved.
  11. **/
  12.  
  13. #include <libraries/bgui.h>
  14. #include <libraries/bgui_macros.h>
  15. #include <intuition/icclass.h>
  16.  
  17. #include <clib/alib_protos.h>
  18.  
  19. #include <proto/exec.h>
  20. #include <proto/bgui.h>
  21. #include <proto/intuition.h>
  22. #include <proto/graphics.h>
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26.  
  27. #include "areaclass.h"
  28.  
  29. /*
  30. **    Compiler stuff.
  31. **/
  32. #ifdef _DCC
  33. #define SAVEDS __geta4
  34. #define ASM
  35. #define REG(x) __ ## x
  36. #else
  37. #define SAVEDS __saveds
  38. #define ASM __asm
  39. #define REG(x) register __ ## x
  40. #endif
  41.  
  42. struct Library *BGUIBase;
  43. Class           *AreaClass;
  44.  
  45. #define ID_REDRAW_AREA        1    /* When this ID is encountered we (re-)render the area. */
  46. #define ID_QUIT                 2
  47.  
  48. /*
  49. **    Simply took from the old BGUIDemo. Renders a simple
  50. **    integer mandel in the area.
  51. **/
  52. ULONG RenderMandel( struct Window *win, struct IBox *ibox, Object *area, Object *wd )
  53. {
  54.     LONG    zr, zi, ar, ai, dr, di, sr, si, st, x, y, i;
  55.     LONG    xsize, ysize, depth, rc;
  56.  
  57.     depth = win->WScreen->BitMap.Depth;
  58.     xsize = ibox->Width;
  59.     ysize = ibox->Height;
  60.  
  61.     sr = 0x400000 / xsize;
  62.     si = 0x300000 / ysize;
  63.     st = 0x140000 * -2;
  64.     zi = 0x180000;
  65.  
  66.     for ( y = ysize - 1; y >= 0; y-- ) {
  67.         zi -= si;
  68.         zr = st;
  69.         for ( x = 0; x < xsize; x++ ) {
  70.             i = 0;
  71.             ar = zr;
  72.             ai = zi;
  73.             do {
  74.                 dr = ar >> 10;
  75.                 di = ai >> 10;
  76.                 ai = dr * 2 * di + zi;
  77.                 dr *= dr;
  78.                 di *= di;
  79.                 ar = dr - di + zr;
  80.                 i++;
  81.             } while (( i <= 25 ) && (( dr + di ) <= 0x400000 ));
  82.             SetAPen( win->RPort, i % ( 1 << depth ));
  83.             WritePixel( win->RPort, x + ibox->Left, y + ibox->Top );
  84.             /*
  85.             **    To keep things simple I sortof duplicated
  86.             **    the event handler here. It simply returns
  87.             **    to the main event handler (below) when
  88.             **    necessary.
  89.             **/
  90.             while (( rc = HandleEvent( wd )) != WMHI_NOMORE ) {
  91.                 if ( rc == ID_REDRAW_AREA || rc == ID_QUIT || rc == WMHI_CLOSEWINDOW )
  92.                     return( rc );
  93.             }
  94.  
  95.             zr += sr;
  96.         }
  97.     }
  98.     return( 0L );
  99. }
  100.  
  101. /*
  102. **    Here we go...
  103. **/
  104. void main( int ac, char **args )
  105. {
  106.     struct Window    *w;
  107.     Object        *Win, *Area, *But;
  108.     ULONG         signal, rc;
  109.     struct IBox    *area_box;
  110.     BOOL         running = TRUE;
  111.  
  112.     if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  113.         /*
  114.         **    Initalize the class.
  115.         **/
  116.         if ( AreaClass = InitAreaClass()) {
  117.             /*
  118.             **    Create AreaClass object.
  119.             **
  120.             **    Note the usage of the ICA_TARGET attribute. This is
  121.             **    required otherwise the object will never notify you
  122.             **    of size changes!!
  123.             **/
  124.             Area = NewObject( AreaClass, NULL, FRM_Type,        FRTYPE_BUTTON,
  125.                                FRM_EdgesOnly,    TRUE,
  126.                                AREA_MinWidth,    40,
  127.                                AREA_MinHeight,    10,
  128.                                GA_ID,        ID_REDRAW_AREA,
  129.                                ICA_TARGET,        ICTARGET_IDCMP,
  130.                                TAG_END );
  131.             /*
  132.             **    Make a window.
  133.             **/
  134.             Win = WindowObject,
  135.                 WINDOW_Title,        "AreaClass demo.",
  136.                 WINDOW_AutoAspect,    TRUE,
  137.                 WINDOW_SmartRefresh,    TRUE,
  138.                 WINDOW_MasterGroup,
  139.                     VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  140.                         GROUP_BackFill,         SHINE_RASTER,
  141.                         StartMember, Area, EndMember,
  142.                         StartMember, But = KeyButton( "_Quit", ID_QUIT ), FixMinHeight, EndMember,
  143.                     EndObject,
  144.             EndObject;
  145.  
  146.             /*
  147.             **    OK?
  148.             **/
  149.             if ( Win ) {
  150.                 /*
  151.                 **    Add gadget key.
  152.                 **/
  153.                 GadgetKey( Win, But, "q" );
  154.                 /*
  155.                 **    Open the window.
  156.                 **/
  157.                 if ( w = WindowOpen( Win )) {
  158.                     /*
  159.                     **    Get window signal.
  160.                     **/
  161.                     GetAttr( WINDOW_SigMask, Win, &signal );
  162.                     /*
  163.                     **    Poll messages...
  164.                     **/
  165.                     do {
  166.                         Wait( signal );
  167.                         while (( rc = HandleEvent( Win )) != WMHI_NOMORE ) {
  168.  
  169.                             handleMsg:
  170.  
  171.                             switch ( rc ) {
  172.  
  173.                                 case    ID_REDRAW_AREA:
  174.                                     /*
  175.                                     **    Were signalled to redraw the
  176.                                     **    area. Obtain the area bounds.
  177.                                     **/
  178.                                     GetAttr( AREA_AreaBox, Area, ( ULONG * )&area_box );
  179.                                     /*
  180.                                     **    Render inside the area.
  181.                                     **    When this routine returns we
  182.                                     **    evaluate the return code.
  183.                                     **/
  184.                                     if ( rc = RenderMandel( w, area_box, Area, Win ))
  185.                                         goto handleMsg;
  186.  
  187.                                     break;
  188.  
  189.                                 case    WMHI_CLOSEWINDOW:
  190.                                 case    ID_QUIT:
  191.                                     running = FALSE;
  192.                                     break;
  193.                             }
  194.                         }
  195.                     } while ( running );
  196.                 }
  197.                 DisposeObject( Win );
  198.             }
  199.             FreeAreaClass( AreaClass );
  200.         }
  201.         CloseLibrary( BGUIBase );
  202.     }
  203. }
  204.  
  205. #ifdef _DCC
  206. int wbmain( struct WBStartup *wbs )
  207. {
  208.     return( main( 0, wbs ));
  209. }
  210. #endif
  211.  
  212.